package com.dp.service.impl3;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import com.dp.pub.SysProperty;
import com.dp.util.BaseBean;
import com.dp.util.BookConfig;
import com.dp.util.DataMap;
import com.dp.util.ImageScalee;
import com.dp.util.InterUtil;
import com.dp.util.PageBean;



@Service
@Transactional
public class JavaBeanImpl extends BaseImpl {
	protected String curdate = (new java.text.SimpleDateFormat("yyyyMM")).format(new Date());
	private static Logger log = Logger.getLogger(JavaBeanImpl.class);
//    public PageBean bookList(DataMap hashMap) {
//        String sql = "select au.*,gen.genre_name ,p.servicename,p.service_code,p.price,au.content_code,p.price_type,p.servicetype,p.access_no,p.content,p.order_success_msg,p.starttime," +
//        		"tac.version,tac.service_count " +
//        		"from t_auditcontents au,t_genre gen,t_service_info p,t_auditapp_content tac " +
//        		"where (au.content_type='3' or au.content_type='10') and au.genre_id=gen.genre_id and au.service_code=p.service_code and au.contentid = tac.contentid";
//
//        Object role_id = hashMap.get("role_id");
//        Object user_id = hashMap.get("user_id");
//        Object content_status = hashMap.get("content_status");
//        Object test_status = hashMap.get("test_status");
//        Object genre_id = hashMap.get("genre_id");
//        Object searchcontentname = hashMap.getMapData("searchcontentname");
//        if(super.StringIsNotNull(role_id) && super.StringIsNotNull(user_id))
//        {
//        	sql = sql + " AND au.user_id='" + user_id + "'";
//        }
//        if (super.StringIsNull(content_status)) {
//            sql = sql + " AND au.content_status='" + content_status + "'";
//        }
//        if (super.StringIsNull(test_status)) {
//            sql = sql + " AND au.test_status='" + test_status + "'";
//        }
//        if (super.StringIsNull(genre_id)) {
//            sql = sql + " AND au.genre_id='" + genre_id + "'";
//        }        
//        if (super.StringIsNull(searchcontentname)) {
//            sql = sql + " AND au.content_name like '%" + searchcontentname + "%'";
//        }
//        
//        String sql2 = "";
//        if(role_id != null && role_id.toString().compareToIgnoreCase("CHANNEL") == 0)
//        {
//    		sql2 = "select distinct au.*,gen.genre_name ,p.servicename,p.service_code,p.price,p.price_type,p.servicetype,p.access_no,p.content,p.order_success_msg,p.starttime," +
//    			"tac.version,tac.service_count " +
//    			"from t_auditapp_content tac,t_genre gen,t_service_info p,t_auditcontents au, " +
//    			"(select contentid from t_resources tr ,(SELECT ts.sourceid FROM t_user tu ,t_employee te,t_spcode ts where tu.user_id='"+user_id+"' and tu.employee_id=te.employee_id and te.sp_code=ts.spcode ) t where tr.distributorid = t.sourceid ) tt " +
//    			"where (au.content_type='3' or au.content_type='10') and au.contentid=tt.contentid and au.genre_id=gen.genre_id and au.service_code=p.service_code and au.contentid = tac.contentid ";
//        	if (super.StringIsNull(content_status)) {
//                sql2 = sql2 + " AND au.content_status='" + content_status + "'";
//            }
//            if (super.StringIsNull(test_status)) {
//                sql2 = sql2 + " AND au.test_status='" + test_status + "'";
//            }
//            if (super.StringIsNull(genre_id)) {
//                sql2 = sql2 + " AND au.genre_id='" + genre_id + "'";
//            }        
//            if (super.StringIsNull(searchcontentname)) {
//                sql2 = sql2 + " AND au.content_name like '%" + searchcontentname + "%'";
//            }
//        	sql = sql + " union all " + sql2;
//        }
//        sql = sql + " order by content_updateddate desc ";
//        try {
//            hashMap.put("sql", sql);
//            return new PageBean(hashMap);
//        } catch (Exception e) {
//            //e.printStackTrace();
//        	log.info(" bookList fail !!!" +e.getMessage());
//            return null;
//        }
//    }
//    public DataMap getBook(DataMap hashMap) {
//        String sql = "select au.*,gen.genre_name,p.service_code,p.price,p.price_type,p.processClass,tac.* from " +
//        		" t_auditcontents au,t_genre gen,t_service_info p,t_auditapp_content tac " +
//        		" where au.genre_id=gen.genre_id and au.service_code=p.service_code and au.contentid = tac.contentid ";
//        Object content_id = hashMap.get("content_id");
//        if (super.StringIsNull(content_id)) {
//            sql = sql + " and au.contentid='" + content_id + "'";
//        }
//        try {
//        	 return null;
////            return this.queryOneRow(sql);
//        } catch (Exception e) {
//        	log.info(" getBook fail !!!" +e.getMessage());
//            return null;
//        }
//    }  
//    public DataMap getContentById(String contentid) {
////    	String sql = "select * from t_auditcontents c, t_auditapp_content tc WHERE c.contentid=tc.contentid  ";
//        
//    	String sql = "select au.*,gen.genre_name,p.service_code,p.price,p.price_type,tac.* from " +
//		" t_auditcontents au,t_genre gen,t_service_info p,t_auditapp_content tac " +
//		" where au.genre_id=gen.genre_id and au.service_code=p.service_code and au.contentid = tac.contentid ";
//        if (super.StringIsNull(contentid)) {
//            sql = sql + " AND au.contentid='" + contentid + "'";
//        }       
//
//        try {
//        	 return null;
////            return new DBOperate().queryOneRow(sql);
//        } catch (Exception e) {
//        	log.info(" getContentById fail !!!" +e.getMessage());
//            return null;
//        }
//    } 
    public ArrayList getChooseChannelByContentId(String contentid) {
//    	String sql = "select * from t_auditcontents c, t_auditapp_content tc WHERE c.contentid=tc.contentid  ";
        
    	String sql = "select tc.channel_id,tc.service_code,tc.channel_name,tc.channel_comment,tc.function_name,tc.status,tc.ordered,tc.created_date,tc.previous_id,tc.primal_id,tc.level,tc.channel_type,tc.channel_hot_topics,tc.channel_classifying_label" +
    			" from t_channels tc,t_channel_auditcontent tca where tc.channel_id=tca.channel_id ";
        if (super.StringIsNull(contentid)) {
            sql = sql + " AND tca.contentid='" + contentid + "'";
        }       

        try {
        	return this.queryALLResultSet(sql);
        } catch (Exception e) {
        	log.info(" getChooseChannelByContentId fail !!!" +e.getMessage());
            return null;
        }
    }
//    public ArrayList getResouceByContentId(String contentid) {
//    	String sql = "select tr.*,group_concat(ua_class_info) ua_class_info from t_auditcontents tc , t_resources tr left join t_ua_class tuc on " +
//    			"FIND_IN_SET(tuc.ua_class_id,tr.useragents) >0, t_resource_auditcontent rc " +
//    			"WHERE rc.resourceid=tr.resourceid and tc.contentid=rc.contentid ";
//        
//        if (super.StringIsNull(contentid)) {
//            sql = sql + " AND rc.contentid='" + contentid + "'";
//        }
//        sql = sql + " group by tr.resourceid";
//        try {
//            return this.queryALLResultSet(sql);
//        } catch (Exception e) {
//        	log.info(" getResouceByContentId fail !!!" +e.getMessage());
//            return null;
//        }
//    }
//    
    public String getSpcode(String userid) {
     
        if (super.StringIsNull(userid)) {
            sql = "select te.sp_code from t_employee te, t_user tu where tu.employee_id=te.employee_id and tu.user_id='" + userid + "'";
        }
        try {
            return this.getOneString();
        } catch (Exception e) {
        	log.info(" getSpcode fail !!!" +e.getMessage());
            return null;
        }
    } 
    
    public String getSpcodeByContentid(String content_id) {
            
        if (super.StringIsNull(content_id)) {
        	sql = "SELECT te.sp_code FROM t_user tu , t_employee te,t_auditcontents tc where " +
    		"tu.employee_id=te.employee_id and  tu.user_id =tc.user_id and tc.contentid='" + content_id + "'";
        }
        try {
            String spcode = this.getOneString();
            if("".equals(spcode))
            		spcode = "00";
            return spcode;
        } catch (Exception e) {
        	log.info(" getSpcodeByContentid fail !!!" +e.getMessage());
            return null;
        }
    }  
    
    public DataMap getResource(String  resourceid) {

    	String sql = "select * from t_resources where resourceid= '" + resourceid + "'";
        try {
        	 return null;
//            return new DBOperate().queryOneRow(sql);
        } catch (Exception e) {
        	log.info(" getResource fail !!!" +e.getMessage());
            return null;
        }
    }
      

    public ArrayList getFileList(DataMap hashMap) {
        String sql = "select  ch.channel_id  ,ch.service_code,ch.channel_name,ch.channel_comment ,ch.function_name,ch.STATUS ,ch.ordered ,ch.created_date" +
				",ch.previous_id ,ch.primal_id ,ch.LEVEL ,ch.channel_type  ,ch.channel_hot_topics ,ch.channel_classifying_label" +"  from t_channels ch,t_user_channels uc WHERE ch.channel_id=uc.channel_id AND status='"+BookConfig.channel_status_enable+"' AND (function_name='"+BookConfig.channel_last+"' OR function_name='"+BookConfig.channel_song+"') ";

        Object employee_id = hashMap.get("employee_id");
        if (super.StringIsNull(employee_id)) {
            sql = sql + " AND uc.employee_id='" + employee_id + "'";
        }
        
        try {
            return this.queryALLResultSet(sql);
        } catch (Exception e) {
        	log.info(" getFileList fail !!!" +e.getMessage());
            return null;
        }
    }
    
    public ArrayList getChannelList(DataMap hashMap) {
        String sql = "select  ch.channel_id  ,ch.service_code,ch.channel_name,ch.channel_comment ,ch.function_name,ch.STATUS ,ch.ordered ,ch.created_date" +
				",ch.previous_id ,ch.primal_id ,ch.LEVEL ,ch.channel_type  ,ch.channel_hot_topics ,ch.channel_classifying_label" +"  from t_channels ch WHERE 1=1 " +
        		"and channel_type='"+BookConfig.channel_type_game+"' " +
        		"and status='"+BookConfig.channel_status_enable+"' " +
        		"and (function_name='"+BookConfig.channel_song+"' OR function_name='"+BookConfig.channel_last+"')";
        Object employee_id = hashMap.get("employee_id");
        Object role_id = hashMap.get("role_id");
        if(role_id != null)
        {
	        if (!role_id.equals("") && super.StringIsNull(employee_id)) {
	            sql = "select  ch.channel_id  ,ch.service_code,ch.channel_name,ch.channel_comment ,ch.function_name,ch.STATUS ,ch.ordered ,ch.created_date" +
				",ch.previous_id ,ch.primal_id ,ch.LEVEL ,ch.channel_type  ,ch.channel_hot_topics ,ch.channel_classifying_label" +"  from t_channels ch,t_user_channels uc WHERE 1=1 " +
	            "and channel_type='"+BookConfig.channel_type_game+"' " +
	            "and ch.channel_id=uc.channel_id " +
	            "and status='"+BookConfig.channel_status_enable+"' " +
	            "and (function_name='"+BookConfig.channel_last+"' OR function_name='"+BookConfig.channel_song+"') " +
	            "and uc.employee_id='" + employee_id + "'";
	        }
        }
        try {
            return this.queryALLResultSet(sql);
        } catch (Exception e) {
        	log.info(" getChannelList fail !!!" +e.getMessage());
            return null;
        }
        
    }
    
    public ArrayList getChooseChannel(DataMap hashMap) {
        String sql = "select  ch.channel_id  ,ch.service_code,ch.channel_name,ch.channel_comment ,ch.function_name,ch.STATUS ,ch.ordered ,ch.created_date" +
				",ch.previous_id ,ch.primal_id ,ch.LEVEL ,ch.channel_type  ,ch.channel_hot_topics ,ch.channel_classifying_label" +"  from t_channels ch,t_channel_auditcontent ca ";
        sql=sql+"WHERE  status='"+BookConfig.channel_status_enable+"' AND (function_name='"+BookConfig.channel_last+"' OR function_name='"+BookConfig.channel_song+"') ";
        sql=sql+" and ca.channel_id=ch.channel_id ";
        Object content_id = hashMap.get("content_id");
        if (super.StringIsNull(content_id)) {
            sql = sql + " AND ca.contentid='" + content_id + "'";
        }
        
        try {
            return this.queryALLResultSet(sql);
        } catch (Exception e) {
        	log.info(" getChooseChannel fail !!!" +e.getMessage());
            return null;
        }
    }

    public ArrayList getChooseResource(DataMap hashMap) {
    	String sql = "";
    	Object content_id = hashMap.get("content_id");
    	if (super.StringIsNull(content_id)) {
    		sql = "select group_concat(ua_class_info) ua_class_info,tr.* from t_resources tr left join t_ua_class tuc on FIND_IN_SET(tuc.ua_class_id,tr.useragents) >0, " +
    				"t_resource_auditcontent trc where trc.resourceid = tr.resourceid and trc.contentid='" + content_id + "' group by tr.resourceid";
        }
        
        try {
            return this.queryALLResultSet(sql);
        } catch (Exception e) {
        	log.info(" getChooseResource fail !!!" +e.getMessage());
            return null;
        }
    }
    
//    public ArrayList getChooseResourceBySourceid(DataMap hashMap) {
//    	Object userid = hashMap.get("user_id");
//    	String sql = "";
//    	if (super.StringIsNull(userid)) {
//        sql = "select tr.*,group_concat(ua_class_info) ua_class_info from  t_resources tr ,t_ua_class tuc , " +
//        		"(SELECT ts.sourceid FROM t_user tu ,t_employee te,t_spcode ts where tu.user_id='"+userid+"' and tu.employee_id=te.employee_id and te.sp_code=ts.spcode ) t " +
//        		"where tr.distributorid = t.sourceid and FIND_IN_SET(tuc.ua_class_id,tr.useragents) >0 ";
//    	}
//        Object content_id = hashMap.get("content_id");
//        if (super.StringIsNull(content_id)) {
//            sql = sql + " AND tr.contentid='" + content_id + "'";
//        }
//        sql = sql + " group by tr.resourceid";
//        try {
//            return this.queryALLResultSet(sql);
//        } catch (Exception e) {
//        	log.info(" getChooseResourceBySourceid fail !!!" +e.getMessage());
//            return null;
//        }
//    }
    
    public ArrayList getNotChooseChannel(DataMap hashMap) {
    	String sql = "select  ch.channel_id  ,ch.service_code,ch.channel_name,ch.channel_comment ,ch.function_name,ch.STATUS ,ch.ordered ,ch.created_date" +
				",ch.previous_id ,ch.primal_id ,ch.LEVEL ,ch.channel_type  ,ch.channel_hot_topics ,ch.channel_classifying_label" +"  from t_channels ch WHERE 1=1 " +
    			"and channel_type='"+BookConfig.channel_type_game+"' " +
    			"and status='"+BookConfig.channel_status_enable+"' " +
    			"and (function_name='"+BookConfig.channel_last+"' OR function_name='"+BookConfig.channel_song+"') ";
        Object role_id = hashMap.get("role_id");
        Object employee_id = hashMap.get("employee_id");
        if(role_id != null)
        {
	        if (!role_id.equals("") && super.StringIsNull(employee_id)) {
	            sql = "select  ch.channel_id  ,ch.service_code,ch.channel_name,ch.channel_comment ,ch.function_name,ch.STATUS ,ch.ordered ,ch.created_date" +
				",ch.previous_id ,ch.primal_id ,ch.LEVEL ,ch.channel_type  ,ch.channel_hot_topics ,ch.channel_classifying_label" +"  from t_channels ch,t_user_channels uc WHERE 1=1 " +
	            		"and ch.channel_id=uc.channel_id " +
	            		"and channel_type='"+BookConfig.channel_type_game+"' " +
	            		"and status='"+BookConfig.channel_status_enable+"' " +
	            		"and (function_name='"+BookConfig.channel_last+"' OR function_name='"+BookConfig.channel_song+"')  " +
	            		"and uc.employee_id='" + employee_id + "'";
	        }
        }
        Object content_id = hashMap.get("content_id");
        if (super.StringIsNull(content_id)) {
            sql = sql + " and ch.channel_id not in (select channel_id from t_channel_auditcontent ca where ";
            sql = sql + " ca.contentid='" + content_id + "')";
        }
        
        try {
            return this.queryALLResultSet(sql);
        } catch (Exception e) {
        	log.info(" getNotChooseChannel fail !!!" +e.getMessage());
            return null;
        }
    }
    
    /**
	 * 得到渠道推广的资源文件
	 */
//    public ArrayList getDisResource(DataMap hashMap) {
//        String sql = " SELECT t.*,group_concat(ua_class_info) ua_class_info,ts.spcode discode " +
//        		"FROM t_spcode ts,t_resources t left join t_ua_class tuc on FIND_IN_SET(tuc.ua_class_id,t.useragents) >0 where t.distributorid != '00' and ts.sourceid=t.distributorid  ";
//        Object content_id = hashMap.get("content_id");
//        if (super.StringIsNull(content_id)) {
//            sql = sql + " AND t.contentid='" + content_id + "'";
//        }
//        sql = sql + " group by t.resourceid";
//        try {
//            return this.queryALLResultSet(sql);
//        } catch (Exception e) {
//        	log.info(" getDisResource fail !!!" +e.getMessage());
//            return null;
//        }
//    }
    
//    public ArrayList getContentResource(DataMap hashMap) {
//    	String sql = "SELECT ta.*,tc.url FROM t_auditcontents ta,t_resource_auditcontent t,t_resources tc " +
//    			"where t.contentid=ta.contentid and tc.resourceid=t.resourceid  ";
//
//        
//        Object content_id = hashMap.get("content_id");
//        if (super.StringIsNull(content_id)) {
//            sql = sql + " AND ta.contentid='" + content_id + "'";
//        }
//        
//        try {
//            return this.queryALLResultSet(sql);
//        } catch (Exception e) {
//            return null;
//        }
//    }
    
//    public ArrayList getGenreAll() {
//        String sql = "select * from t_genre where conent_type='3' or conent_type='10'";
//        try {
//            return this.queryALLResultSet(sql);
//        } catch (Exception e) {
//        	log.info(" getGenreAll fail !!!" +e.getMessage());
//            return null;
//        }
//    }
//    
//    public ArrayList getContentsByGenreId(String genreid,String roleid, String userid)
//    {
//    	String sql = "";
//    	if(roleid != null)
//    	{
//    		if (super.StringIsNull(genreid) && super.StringIsNull(userid)) 
//    		sql = "SELECT * FROM t_auditcontents t where t.genre_id='" + genreid + "'  and t.user_id='" + userid + "' and t.test_status = '0'";
//    	}
//    	else
//    	{
//	    	if (super.StringIsNull(genreid)) 
//	    	{
//	    		sql = "SELECT * FROM t_auditcontents t where t.genre_id='" + genreid + "'" + " and t.test_status = '0'";
//	        }
//    	}
//    	try {
//            return this.queryALLResultSet(sql);
//        } catch (Exception e) {
//        	log.info(" getContentsByGenreId fail !!!" +e.getMessage());
//            return null;
//        }
//    }
    
    public ArrayList getMobileCompany(DataMap hashMap) {
        String sql = "SELECT t.com_id,t.com_name FROM t_mobile_company_info t where 1=1 ";
        try {
            return this.queryALLResultSet(sql);
        } catch (Exception e) {
        	log.info(" getMobileCompany fail !!!" +e.getMessage());
            return null;
        }
    }
    
    public ArrayList getUaClass(String comid) {
        String sql = "SELECT t.UA_CLASS_ID,t.UA_CLASS, t.ua_class_info FROM t_ua_class t where com_id= " + comid;
        
        try {
            return this.queryALLResultSet(sql);
        } catch (Exception e) {
        	log.info(" getUaClass fail !!!" +e.getMessage());
            return null;
        }
    }
    
//    public ArrayList getPriceAll(DataMap hashMap) {
//        String sql = "select p.* from t_service_info p,t_user_prices up where p.service_code=up.service_code ";
//        
//        Object employee_id = hashMap.get("employee_id");
//        Object role_id = hashMap.get("role_id");
//        if(role_id != null)
//        {
//	        if (!role_id.equals("") && super.StringIsNull(employee_id)) {
//	            sql = sql + " AND employee_id='" + employee_id + "'";
//	        }
//        }
//        else if(role_id == null || role_id.equals(""))
//        {
//        	sql = "select p.* from t_service_info p ";
//        }
//        try {
//            return this.queryALLResultSet(sql);
//        } catch (Exception e) {
//        	log.info(" getPriceAll fail !!!" +e.getMessage());
//            return null;
//        }
//    }
    //只取计费点业务
//    public ArrayList getPriceOrder(DataMap hashMap) {
//        String sql = "select p.* from t_service_info p,t_user_prices up where p.servicetype='6' and p.service_code=up.service_code ";
//        
//        Object employee_id = hashMap.get("employee_id");
//        Object role_id = hashMap.get("role_id");
//        if(role_id != null)
//        {
//	        if (!role_id.equals("") && super.StringIsNull(employee_id)) {
//	            sql = sql + " AND employee_id='" + employee_id + "'";
//	        }
//        }
//        else if(role_id == null || role_id.equals(""))
//        {
//        	sql = "select p.* from t_service_info p where p.servicetype='6'";
//        }
//        try {
//            return this.queryALLResultSet(sql);
//        } catch (Exception e) {
//        	log.info(" getPriceOrder fail !!!" +e.getMessage());
//            return null;
//        }
//    }
    
//    public ArrayList getBillingPoint(DataMap hashMap) {
//        String sql = "select bp.* from t_billingpoint_service bp where 1=1 ";;
//        
//        Object content_id = hashMap.get("content_id"); 
//        if (super.StringIsNull(content_id)) {
//            sql = sql + " and contentid='" + content_id + "'";
//        }
//        
//        try {
//            return this.queryALLResultSet(sql);
//        } catch (Exception e) {
//        	log.info(" getBillingPoint fail !!!" +e.getMessage());
//            return null;
//        }
//    }
    
    public ArrayList getAllDistributor(DataMap hashMap) {
    	//add group by tr.role_id 由于列出全部sp关联用户和角色，所以会有多个sp情况出现，所以按spcode分组
		String sql = "SELECT tu.user_id,te.employee_id,tr.role_id,ts.spcode,ts.spname,ts.sourceid " +
				"FROM t_user tu , t_roles tr, t_employee te,t_spcode ts where  tr.role_type='CHANNEL' and tu.role_id = tr.role_id " +
				"and tu.employee_id=te.employee_id and te.sp_code=ts.spcode group by ts.spcode";
		try {
            return this.queryALLResultSet(sql);
        } catch (Exception e) {
        	log.info(" getAllDistributor fail !!!" +e.getMessage());
            return null;
        }
	}
    
//    public ArrayList getAuthorAll() {
//        String sql = "select * from t_author ";
//        try {
//            return this.queryALLResultSet(sql);
//        } catch (Exception e) {
//        	log.info(" getAuthorAll fail !!!" +e.getMessage());
//            return null;
//        }
//    }    
    
//    public ArrayList getPublishAll() {
//        String sql = "select * from t_publish ";
//        try {
//            return this.queryALLResultSet(sql);
//        } catch (Exception e) {
//        	log.info(" getPublishAll fail !!!" +e.getMessage());
//            return null;
//        }
//    }    
    //modify:add insert into news_contenttitle  news_extends_channel_title
    public boolean insertAuditContent(DataMap hashMap) {
        StringBuffer sql_auditcontents = new StringBuffer();
        sql_auditcontents.append("insert into t_auditcontents (contentid,genre_id,service_code,user_id,content_name,content_keyword,content_pubdate," +
        		"content_duration,conten_info,content_type,content_updateddate,Copyright_deadline,content_status,test_status,audituser," +
        		"pub_company,area,lastservice_code,ordered,cause,content_code,order_success_msg) values (" );
        //t_auditcontents columns
        String content_id = super.ObjectToStringDB(hashMap.get("auditcontent_id"));
        String genre_id = super.ObjectToStringDB(hashMap.get("genre_id"));
        String service_code = super.ObjectToStringDB(hashMap.get("service_code"));
        String user_id = super.ObjectToStringDB(hashMap.get("user_id"));        
        String content_name = super.ObjectToStringDB(hashMap.get("content_name"));
        String content_keyword = super.ObjectToStringDB(hashMap.get("content_keyword"));
        String content_pubdate = super.ObjectToStringDB(hashMap.get("content_pubdate"));
        if(content_pubdate == null || content_pubdate.equals("null"))
        {
        	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			Date date = new Date();
			content_pubdate = "'"+sdf.format(date)+"'";
        }
        String content_duration = super.ObjectToStringDB(hashMap.get("content_duration"));
        String conten_info = super.ObjectToStringDB(hashMap.get("conten_info"));        
//        String contenttype = super.ObjectToStringDB("3");
        String contenttype = super.ObjectToStringDB(hashMap.get("content_type"));
        String nowtime = super.getNowTime();
        String update_date = super.ObjectToStringDB(nowtime);
        String Copyright_deadline = super.ObjectToStringDB(hashMap.get("Copyright_deadline"));
        if(Copyright_deadline == null || Copyright_deadline.equals("null"))
        {
        	Copyright_deadline = "'2037-12-31'";
        }
        String content_status = super.ObjectToStringDB("new");//super.ObjectToStringDB(hashMap.get("status"));
        String test_status = super.ObjectToStringDB("0");
        String audituser = super.ObjectToStringDB(hashMap.get("audituser"));
//        String lastservice_code = service_code;// add new content lastservicecode = servicecode
        String pub_company = super.ObjectToStringDB(hashMap.get("pub_company"));
        String area = super.ObjectToStringDB(hashMap.get("area"));
        String ordered = super.ObjectToStringDB(hashMap.get("ordered"));
        String cause = super.ObjectToStringDB(hashMap.get("cause"));
        String content_code = super.ObjectToStringDB(hashMap.get("content_code"));
        String order_success_msg = super.ObjectToStringDB(hashMap.get("order_success_msg"));
        sql_auditcontents.append(content_id);
        sql_auditcontents.append(",");
        sql_auditcontents.append(genre_id);
        sql_auditcontents.append(",");
        sql_auditcontents.append(service_code);
        sql_auditcontents.append(",");
        sql_auditcontents.append(user_id);
        sql_auditcontents.append(",");
        sql_auditcontents.append(content_name);
        sql_auditcontents.append(",");
        sql_auditcontents.append(content_keyword);
        sql_auditcontents.append(",");
        sql_auditcontents.append(content_pubdate);
        sql_auditcontents.append(",");
        sql_auditcontents.append(content_duration);
        sql_auditcontents.append(",");
        sql_auditcontents.append(conten_info);
        sql_auditcontents.append(",");
        sql_auditcontents.append(contenttype);
        sql_auditcontents.append(",");
        sql_auditcontents.append(update_date);
        sql_auditcontents.append(",");
        sql_auditcontents.append(Copyright_deadline);
        sql_auditcontents.append(",");
        sql_auditcontents.append(content_status);
        sql_auditcontents.append(",");
        sql_auditcontents.append(test_status);
        sql_auditcontents.append(",");
        sql_auditcontents.append(audituser);
        sql_auditcontents.append(",");
        sql_auditcontents.append(pub_company);
        sql_auditcontents.append(",");
        sql_auditcontents.append(area);
        sql_auditcontents.append(",");
        sql_auditcontents.append(service_code);//new content lastservice_code == service_code
        sql_auditcontents.append(",");
        sql_auditcontents.append(ordered);
        sql_auditcontents.append(",");
        sql_auditcontents.append(cause);
        sql_auditcontents.append(",");
        sql_auditcontents.append(content_code);
        sql_auditcontents.append(",");
        sql_auditcontents.append(order_success_msg);
        sql_auditcontents.append(")");
        
        StringBuffer sql_auditapp_content = new StringBuffer();
        sql_auditapp_content.append("insert into t_auditapp_content (contentid,strategy,language,online,version,cldc_version,midp_version," +
        		"audituser,ordered,service_count) values ("); 
        //t_auditapp_content columns:strategy,language,online,content_size,version,cldc_version,midp_version
        String strategy = super.ObjectToStringDB(hashMap.get("strategy"));
        String language = super.ObjectToStringDB(hashMap.get("language"));
        String online = super.ObjectToStringDB(hashMap.get("online"));
        String version = super.ObjectToStringDB(hashMap.get("version"));
        String cldc_version = super.ObjectToStringDB(hashMap.get("cldc_version"));
        String midp_version = super.ObjectToStringDB(hashMap.get("midp_version"));
        String service_count = super.ObjectToStringDB(hashMap.get("service_count"));
        if(service_count == null || service_count.equals("") || service_count.equals("null"))
        {
        	service_count = super.ObjectToStringDB("0");
        }
        sql_auditapp_content.append(content_id);
        sql_auditapp_content.append(",");
        sql_auditapp_content.append(strategy);
        sql_auditapp_content.append(",");
        sql_auditapp_content.append(language);
        sql_auditapp_content.append(",");
        sql_auditapp_content.append(online);
        sql_auditapp_content.append(",");
        sql_auditapp_content.append(version);
        sql_auditapp_content.append(",");
        sql_auditapp_content.append(cldc_version);
        sql_auditapp_content.append(",");
        sql_auditapp_content.append(midp_version);
        sql_auditapp_content.append(",");
        sql_auditapp_content.append(audituser);
        sql_auditapp_content.append(",");
        sql_auditapp_content.append(ordered);
        sql_auditapp_content.append(",");
        sql_auditapp_content.append(service_count);
        sql_auditapp_content.append(")");
        
        //update phase2  insert news_contenttitle
//        String contenticon = super.ObjectToString(hashMap.get("contenticon"));
        String contenticon = SysProperty.getPrep("sysiconid_title");
        if(contenticon == null || contenticon.equals(""))
        	contenticon = "1";
        String contenttext = "'"+InterUtil.rb.getString("src.gamename")+":"+super.ObjectToString(hashMap.get("content_name"))+"@"+InterUtil.rb.getString("src.devcompany")+":"+super.ObjectToString(hashMap.get("pub_company"))
							+"@"+InterUtil.rb.getString("src.language")+":"+super.ObjectToString(hashMap.get("language"))+"@"+InterUtil.rb.getString("src.online")+":"+super.ObjectToString(hashMap.get("online"))+"@"+InterUtil.rb.getString("src.version")+":"+
							super.ObjectToString(hashMap.get("version"))+"@"+InterUtil.rb.getString("src.updatetime")+":"+nowtime+"@"+InterUtil.rb.getString("src.gameintro")+":"+
							super.ObjectToString(hashMap.get("conten_info"))+"@"+InterUtil.rb.getString("src.gamesta")+":"+super.ObjectToString(hashMap.get("strategy"))+"'";
        String newstype = "'"+InterUtil.rb.getString("src.game")+"'";
        StringBuffer insertNewsContentTitle = new StringBuffer();
        insertNewsContentTitle.append("insert into news_contenttitle (contentid,contenttitle,contenticon,contenttext,newstype) values (");
        insertNewsContentTitle.append(content_id);
        insertNewsContentTitle.append(",");
        insertNewsContentTitle.append(content_name);
        insertNewsContentTitle.append(",");
        insertNewsContentTitle.append(contenticon);
        insertNewsContentTitle.append(",");
        insertNewsContentTitle.append(contenttext);
        insertNewsContentTitle.append(",");
        insertNewsContentTitle.append(newstype);
        insertNewsContentTitle.append(")");
        //---------
        
        String res=(String)hashMap.get("resourceid");
        String [] resid=res.split(",");
        
        String channels=(String)hashMap.get("channelid");
        String [] channelid=channels.split(",");
        
        
        String tempSql="insert into t_channel_auditcontent(contentid,channel_id)VALUES( "+content_id + ",";
        //phase2
        String newChSql="insert into news_extends_channel_title(channleid,cid,contentstatus,istest,isnew)VALUES(";
        
        ArrayList<String> sqlStrList = new ArrayList<String>();
        sqlStrList.add(sql_auditcontents.toString());
        sqlStrList.add(sql_auditapp_content.toString());
        //phase2  insert news_contenttitle
        sqlStrList.add(insertNewsContentTitle.toString());
        
        for(int i=0;i<channelid.length;i++)
        {
        	sqlStrList.add(tempSql+"'"+channelid[i]+"')");
        	sqlStrList.add(newChSql+"(select channleid from news_extends_channel where channel_id='"+channelid[i]+"'),(select LAST_INSERT_ID()),0,0,1)");
        }
        
        tempSql="insert into t_resource_auditcontent(contentid,resourceid)VALUES( "+content_id + ",";
        for(int i=0;i<resid.length;i++)
        {
        	sqlStrList.add(tempSql+"'"+resid[i]+"')");
        }
        int serviceCountNum = Integer.parseInt(service_count.replace("'", ""));
        if(serviceCountNum > 0)
        {
	        for(int i = 1;i <= serviceCountNum; i++)
	        {
	        	StringBuffer sql_billingpoint_service = new StringBuffer();	        
		        sql_billingpoint_service.append("insert into t_billingpoint_service (contentid,billingpoint,comment,service_code) values (");
		        sql_billingpoint_service.append(content_id);
		        sql_billingpoint_service.append(",");
		        if(i<10)
		        	sql_billingpoint_service.append("'0"+i+"'");
		        else
		        	sql_billingpoint_service.append("'"+i+"'");
	        	sql_billingpoint_service.append(",");
	        	sql_billingpoint_service.append("null");
	        	sql_billingpoint_service.append(",");
	        	sql_billingpoint_service.append(super.ObjectToStringDB(hashMap.get("service_point_" + i)));
	        	sql_billingpoint_service.append(")");
	        	sqlStrList.add(sql_billingpoint_service.toString());
	        }
        }
        
//        String[] sqlStr = sqlStrList.toArray(new String[channelid.length*2+resid.length+2+serviceCountNum+1]);
        String[] sqlStr = sqlStrList.toArray(new String[sqlStrList.size()]);
        try {
            return this.execTransaction(sqlStr);
        } catch (Exception e) {
        	log.info(" insertAuditContent fail !!!" +e.getMessage());
            return false;
        }
    }
     
    public boolean delAuditContent(DataMap hashMap)  {
        Object content_id = hashMap.get("content_id");
        String content_status = (String)hashMap.get("content_status");
        String [] sqlStr=new String[6];
        String sql = "delete from t_auditcontents where contentid='" + content_id + "'";
        
        String sqlInsert = "insert into t_resourcedelete (spcode,type,url,format) " +
        		"(select tr.spcode,tr.type,tr.url,tr.format from t_resource_auditcontent tra,t_resources tr where tra.resourceid=tr.resourceid and tra.contentid='" + content_id + "')";
        String sql1 = "delete from t_channel_auditcontent where contentid='" + content_id + "'";
        
        String sql2 = "delete from t_resource_auditcontent where contentid='" + content_id + "'";
        
        String sqlDelBillingPoint = "delete from t_billingpoint_service where contentid='" + content_id + "'";
        
        String sqlDelAuditAppContent = "delete from t_auditapp_content where contentid='" + content_id + "'";
        sqlStr[0]=sql;
        sqlStr[1]=sqlInsert;
        sqlStr[2]=sql1;
        sqlStr[3]=sql2;
        sqlStr[4]=sqlDelBillingPoint;
        sqlStr[5]=sqlDelAuditAppContent;
        try {
        	boolean bool=this.execTransaction(sqlStr);
        	if(bool&&content_status.equals("pass"))
        	{
        		delPassContent(hashMap);
        	}
            return bool;
        } catch (Exception e) {
        	log.info(" delAuditContent fail !!!" +e.getMessage());
            return false;
        }
    }    
    
    public boolean delPassContent(DataMap hashMap)  {
        Object content_id = hashMap.get("content_id");
        String [] sqlStr=new String[5];
        String sql = "delete from t_contents where contentid='" + content_id + "'";
        
        String sql1 = "delete from t_channel_contents where contentid='" + content_id + "'";
        
        String sql2 = "delete from t_resources where resourceid in (select resourceid from t_resource_content where contentid='" + content_id + "')";
        
        String sql3 = "delete from t_resource_content where contentid='" + content_id + "'";
        
        String sqlDelAppContent = "delete from t_application_content where contentid='" + content_id + "'";
        sqlStr[0]=sql;
        sqlStr[1]=sql1;
        sqlStr[2]=sql2;
        sqlStr[3]=sql3;
        sqlStr[4]=sqlDelAppContent;
        try {
            return this.execTransaction(sqlStr);
        } catch (Exception e) {
        	log.info(" delPassContent fail !!!" +e.getMessage());
            return false;
        }
    }    
    
    public boolean delResourceById(String resourceid,String content_id)  {
    	ArrayList<String> sqlStrList = new ArrayList<String>();
        String sql1 = "";
        String sql2 = "";
        String sqlInsert = "";
        String deleteNews = "";
        if(resourceid != null && !resourceid .equals(""))
        {
        	sqlInsert = "insert into t_resourcedelete (spcode,type,url,format) (select tr.spcode,tr.type,tr.url,tr.format from t_resources tr where tr.resourceid='" + resourceid + "')";
        	sqlStrList.add(sqlInsert);
        	sql1 = "delete from t_resources where resourceid='" + resourceid + "'";
        	sqlStrList.add(sql1);
        	deleteNews = "delete from news_resources where name='"+ resourceid + "'";
        	sqlStrList.add(deleteNews);
        }
        sql2 = "delete from t_resource_auditcontent where resourceid='" + resourceid + "'";
        if(content_id != null && !content_id .equals(""))
        {
        	sql2 = sql2 + " and contentid='" + content_id +"'";
        }
        sqlStrList.add(sql2);
        try {
        	boolean bool=this.execTransaction(sqlStrList);
            return bool;
        } catch (Exception e) {
        	log.info(" delResourceById fail !!!" +e.getMessage());
            return false;
        }
    }    
    
    //  disable didnot delete resource
    // modify add update status at news_extends_channel_title
    // add delete from news_contentresource
    public boolean disableContentDAO(DataMap hashMap) {
    	Object content_id = hashMap.get("content_id");
        String sql1 = "update t_auditcontents set content_status='disable',test_status='0' where contentid = '" + content_id + "'";
//        String sql2 = "update t_auditapp_content set service_count='0' where contentid = '" + content_id + "'";
        String sql3 = "delete from t_channel_auditcontent where contentid='" + content_id + "'";
        String sql4 = "delete from t_channel_contents where contentid='" + content_id + "'";
        
        //phase2
        String sql5 = "update news_extends_channel_title set contentstatus=3 where cid=(SELECT cid FROM news_contenttitle where contentid='"+content_id+"')";
//        String sql5 = "update t_billingpoint_service set comment='disable' where contentid='" + content_id + "'";
        
        String sql6 = "delete from t_contents where contentid='" + content_id + "'";
        String sql7 = "delete from t_application_content where contentid='" + content_id + "'";
        
        String sql8 = "delete from t_resource_content where contentid='" + content_id + "'";
        
        String sql9 = "delete from news_contenresource where cid=(SELECT cid FROM news_contenttitle where contentid='"+content_id+"')";
        
        String [] sqlStr=new String[9];
        sqlStr[0]=sql1;
//        sqlStr[1]=sql2;
        sqlStr[2]=sql3;
        sqlStr[3]=sql4;
        sqlStr[4]=sql5;
        sqlStr[5]=sql6;
        sqlStr[6]=sql7;
        sqlStr[7]=sql8;
        sqlStr[8]=sql9;
        try {
            return this.execTransaction(sqlStr);
        } catch (Exception e) {
        	log.info(" disableContentDAO fail !!!" +e.getMessage());
            return false;
        }
    }
    
    //  enable
//    public boolean enableContent(DataMap hashMap,String status) {
//    	String content_id = (String)hashMap.get("content_id");
//        String sql = "update t_auditcontents set content_status='"+status+"' where contentid = '" + content_id + "'";
//        
//        try {
//            return .updateNativeQuery(sql);
//        } catch (Exception e) {
//            return false;
//        }
//    }
    
    //modify add update news_contenttitle
    public boolean updateAuditContent(DataMap hashMap) {
        String sql = "update  t_auditcontents set ";
        String sqlUpdateAuditApp = "update t_auditapp_content set ";
        String content_id = super.ObjectToStringDB(hashMap.get("content_id"));
//        String employee_id = super.ObjectToStringDB(hashMap.get("employee_id"));
//        String user_id = super.ObjectToStringDB(hashMap.get("user_id"));
		String content_name = super.ObjectToStringDB(hashMap.get("content_name"));
        String genre_id = super.ObjectToStringDB(hashMap.get("genre_id"));        
		String content_status = super.ObjectToStringDB("new");
		String content_pubdate = super.ObjectToStringDB(hashMap.get("content_pubdate"));
		String copyright_deadline = super.ObjectToStringDB(hashMap.get("Copyright_deadline"));
        String service_code = super.ObjectToStringDB(hashMap.get("service_code"));
		String ordered = super.ObjectToStringDB(hashMap.get("ordered"));
		String conten_info = super.ObjectToStringDB(hashMap.get("conten_info"));
		String content_type = super.ObjectToStringDB(hashMap.get("content_type"));
		String content_keyword = super.ObjectToStringDB(hashMap.get("content_keyword"));
		String nowtime = super.getNowTime();
		String content_updateddate = super.ObjectToStringDB(nowtime);    
		String content_code = super.ObjectToStringDB(hashMap.get("content_code"));
		String pub_company = super.ObjectToStringDB(hashMap.get("pub_company"));
        String area = super.ObjectToStringDB(hashMap.get("area"));
        String order_success_msg = super.ObjectToStringDB(hashMap.get("order_success_msg"));
		
        String strategy = super.ObjectToStringDB(hashMap.get("strategy"));
        String language = super.ObjectToStringDB(hashMap.get("language"));
        String online = super.ObjectToStringDB(hashMap.get("online"));
        String version = super.ObjectToStringDB(hashMap.get("version"));
        String cldc_version = super.ObjectToStringDB(hashMap.get("cldc_version"));
        String midp_version = super.ObjectToStringDB(hashMap.get("midp_version"));
        String service_count = super.ObjectToStringDB(hashMap.get("service_count"));
        String billingPointChangeFlag = (String)(hashMap.get("billingPointChangeFlag"));
        if(service_count == null || service_count.equals("") || service_count.equals("null"))
        {
        	service_count = super.ObjectToStringDB("0");
        }
        
//        sql = sql + "user_id=" + user_id + ",";
        sql = sql + "content_name=" + content_name + ",";
        sql = sql + "genre_id=" + genre_id + ",";
        sql = sql + "content_status=" + content_status + ","; 
        sql = sql + "content_pubdate=" + content_pubdate + ",";
        sql = sql + "service_code=" + service_code + ",";

        sql = sql + "ordered=" + ordered + ",";
        sql = sql + "conten_info=" + conten_info + ",";
        sql = sql + "content_type=" + content_type + ",";
        sql = sql + "content_keyword=" + content_keyword + ",";        
        sql = sql + "content_updateddate=" + content_updateddate + ",";
        sql = sql + "copyright_deadline=" + copyright_deadline + ",";
        sql = sql + "pub_company=" + pub_company + ",";
        sql = sql + "area=" + area + ",";
        sql = sql + "content_code=" + content_code + ",";
        sql = sql + "order_success_msg=" + order_success_msg + "";

        sqlUpdateAuditApp = sqlUpdateAuditApp + "strategy=" + strategy + ",";
        sqlUpdateAuditApp = sqlUpdateAuditApp + "language=" + language + ",";
        sqlUpdateAuditApp = sqlUpdateAuditApp + "online=" + online + ",";     
        sqlUpdateAuditApp = sqlUpdateAuditApp + "version=" + version + ",";
        sqlUpdateAuditApp = sqlUpdateAuditApp + "cldc_version=" + cldc_version + ",";             
        sqlUpdateAuditApp = sqlUpdateAuditApp + "midp_version=" + midp_version + ",";
        sqlUpdateAuditApp = sqlUpdateAuditApp + "ordered=" + ordered + ",";
        sqlUpdateAuditApp = sqlUpdateAuditApp + "service_count=" + service_count + "";
                
        sql = sql + " where contentid=" + content_id;
        sqlUpdateAuditApp = sqlUpdateAuditApp + " where contentid=" + content_id;
        
        String temp=(String)hashMap.get("channelid");
        String [] channelid=temp.split(",");
        
        //      update phase2  update news_contenttitle
        String sqlUpdateNewsContentTitle = "update news_contenttitle set ";
//        String contenticon = super.ObjectToString(hashMap.get("contenticon"));
        String contenticon = SysProperty.getPrep("sysiconid_title");
        if(contenticon == null || contenticon.equals(""))
        	contenticon = "1";
        String contenttext = "'"+InterUtil.rb.getString("src.gamename")+":"+super.ObjectToString(hashMap.get("content_name"))+"@"+InterUtil.rb.getString("src.devcompany")+":"+super.ObjectToString(hashMap.get("pub_company"))
		+"@"+InterUtil.rb.getString("src.language")+":"+super.ObjectToString(hashMap.get("language"))+"@"+InterUtil.rb.getString("src.online")+":"+super.ObjectToString(hashMap.get("online"))+"@"+InterUtil.rb.getString("src.version")+":"+
		super.ObjectToString(hashMap.get("version"))+"@"+InterUtil.rb.getString("src.updatetime")+":"+nowtime+"@"+InterUtil.rb.getString("src.gameintro")+":"+
		super.ObjectToString(hashMap.get("conten_info"))+"@"+InterUtil.rb.getString("src.gamesta")+":"+super.ObjectToString(hashMap.get("strategy"))+"'";
        sqlUpdateNewsContentTitle = sqlUpdateNewsContentTitle + "contenttitle=" + content_name + ",";
        sqlUpdateNewsContentTitle = sqlUpdateNewsContentTitle + "contenticon=" + contenticon + ",";
        sqlUpdateNewsContentTitle = sqlUpdateNewsContentTitle + "contenttext=" + contenttext;
        sqlUpdateNewsContentTitle = sqlUpdateNewsContentTitle + " where contentid=" + content_id;
        //---------
        
        ArrayList<String> sqlStrList = new ArrayList<String>();
        String sqlDelBillingPoint = "delete from t_billingpoint_service where contentid="+content_id;
        String sqlDelChannelAudit = "delete from t_channel_auditcontent where contentid="+content_id;
//      phase2	
        String sqlDelNewChannel = "delete from news_extends_channel_title where cid=(SELECT cid FROM news_contenttitle where contentid="+content_id+")";
        
        sqlStrList.add(sql);
        sqlStrList.add(sqlUpdateNewsContentTitle);
        sqlStrList.add(sqlUpdateAuditApp);        
        sqlStrList.add(sqlDelChannelAudit);
        sqlStrList.add(sqlDelNewChannel);
        
        String tempSql="insert into t_channel_auditcontent(contentid,channel_id)VALUES( "+content_id + ",";
        //      phase2
        String newChSql="insert into news_extends_channel_title(channleid,cid,contentstatus,istest,isnew)VALUES(";
        for(int i=0;i<channelid.length;i++)
        {
        	sqlStrList.add(tempSql+"'"+channelid[i]+"')");
        	sqlStrList.add(newChSql+"(select channleid from news_extends_channel where channel_id='"+channelid[i]+"')," +
        			"(SELECT cid FROM news_contenttitle where contentid="+content_id+"),0,0,1)");
        }
        
        int serviceCountNum = Integer.parseInt(service_count.replace("'", ""));
	        if(serviceCountNum > 0)
	        {
	        	sqlStrList.add(sqlDelBillingPoint);
		        for(int i = 1;i <= serviceCountNum; i++)
		        {
		        	StringBuffer sql_billingpoint_service = new StringBuffer();	        
			        sql_billingpoint_service.append("insert into t_billingpoint_service (contentid,billingpoint,comment,service_code) values (");
			        sql_billingpoint_service.append(content_id);
			        sql_billingpoint_service.append(",");
		        	sql_billingpoint_service.append("'"+i+"'");
		        	sql_billingpoint_service.append(",");
		        	sql_billingpoint_service.append("null");
		        	sql_billingpoint_service.append(",");
		        	sql_billingpoint_service.append(super.ObjectToStringDB(hashMap.get("service_point_" + i)));
		        	sql_billingpoint_service.append(")");
		        	sqlStrList.add(sql_billingpoint_service.toString());
		        }
	        }
//        }
//        String[] sqlStr = sqlStrList.toArray(new String[channelid.length+3+serviceCountNum]);
        try {
        	boolean bool=this.execTransaction(sqlStrList);
            return bool;
        } catch (Exception e) {
        	log.info(" updateAuditContent fail !!!" +e.getMessage());
            return false;
        }
    }
    
    public String scaleImage(String contentid)
	{
		String sql = "select t.resourceid,t.fullpath from t_resources t,t_resource_auditcontent trac" +
				" where t.type='12' and t.resourceid=trac.resourceid and trac.contentid="+contentid;
		List resList = null;
		String resourceid = "";
		try {
			resList = this.queryALLResultSet(sql);
		
			if(resList.size()>0)
			{
				HashMap<String,String> tmpMap = (HashMap)resList.get(0);
				resourceid = tmpMap.get("resourceid");
				String fullpath = tmpMap.get("fullpath");
				ImageScalee ims = new ImageScalee();
				String imageSizeScaleStr = SysProperty.getPrep("news_imagesizescale");
	        	String imageFormatScaleStr = SysProperty.getPrep("news_imageformatscale");
	        	if(imageFormatScaleStr == null || imageFormatScaleStr.equals(""))
	        		imageFormatScaleStr = "png";
				String[] imageSizeScaleAry = imageSizeScaleStr.split(","); 
				String[] imageFormatScaleAry = imageFormatScaleStr.split(","); 
				if(imageSizeScaleAry != null&&imageSizeScaleAry.length>0)
				{
					for(String imageSizeScale:imageSizeScaleAry)
					{
						String screenWidHei = imageSizeScale.split("@")[0];
						String picWidHei = imageSizeScale.split("@")[1];
						int screenWidth = Integer.parseInt(screenWidHei.split("x")[0]);
						int screenHeight = Integer.parseInt(screenWidHei.split("x")[1]);
						int width = Integer.parseInt(picWidHei.split("x")[0]);
						int height = Integer.parseInt(picWidHei.split("x")[1]);
						if(imageFormatScaleAry!=null && imageFormatScaleAry.length>0)
							for(String imageFormatScale:imageFormatScaleAry)
								ims.compressPicsScale(fullpath, width, height, imageFormatScale, screenWidth, screenHeight);
					}
				}
				String scaleFullPath = fullpath.replace(".", "-p.");
				sql = "insert into news_resources (name,newformat,fullpath) values('"+resourceid+"','"+imageFormatScaleStr+"','"+scaleFullPath+"')";
				this.updateNativeQuery(sql);
			}
		} catch (Exception e) {
			log.info(" parse content icon fail !!!" +e.getMessage());
			e.printStackTrace();
			return null;
		}
		return resourceid;
	}
    
    //modify phase2 如果审核通过 测试通过 则修改内容和栏目关联比表的contentstatus 修改时需要查询对应栏目的更新方式
    public boolean auditPass(DataMap hashMap,String status) {
    	String content_id_list = (String)hashMap.get("content_id_list");
    	
        if(content_id_list!=null && !content_id_list.equals(""))
        {
        	String[] c_id_strList=content_id_list.split(",");
        	for(String contentStr:c_id_strList)
	        {
        		String[] idAndAuditStatus = contentStr.split("/");
	            String content_id = "'" + idAndAuditStatus[0] + "'";
	            String test_status = "'" + idAndAuditStatus[1] + "'";
	            String user_id = super.ObjectToStringDB(hashMap.get("user_id"));
	            ArrayList<String> sqlStrList = new ArrayList<String>();
	            
	        	//修改状态	            
	        	String sql1="update t_auditcontents set content_status='"+status+"',audituser="+user_id+",lastservice_code=service_code where contentid = "+content_id;
	        	String sqlUpDateAuditAppContent = "update t_auditapp_content set audituser="+user_id;
	        	sqlStrList.add(sql1);
	        	sqlStrList.add(sqlUpDateAuditAppContent);
	        	ArrayList chList = null;
	        	//发布 所有表 条件test_status=1 审核通过+测试通过
	        	try {
	        	if(test_status.equals("'1'"))
	        	{
	        		//转换图片 放在上线时做 这样可以避免重新上传文件后还需要审核的情况
		            String resourceid = this.scaleImage(content_id);
		            if(resourceid == null)
		            	return false;
		            else if(resourceid!=null && !resourceid.equals(""))
		            {
		            	String upConIconSql = "update news_contenttitle set contenticon=(select max(rid) from news_resources where name='"+resourceid+"') where contentid="+content_id;
		            	sqlStrList.add(upConIconSql);
		            }
	        		//add phase2 查询对应栏目的更新方式
	        		//modify 0928 not use any more
//	        		chList = db.queryALLResultSet("SELECT nec.channleid,nec.updatetimer,nc.cid FROM news_extends_channel nec,news_extends_channel_title ncc," +
//	        				"news_contenttitle nc where nc.contentid= "+content_id+" and nec.channleid=ncc.channleid and ncc.cid=nc.cid ");
	        		//update news_extends_channel_title where chid cid
//	        		for(int i = 0;i<chList.size();i++)
//	        		{
//	        			DataMap chmap = (DataMap)chList.get(i);
//	        			String chid = (String)chmap.get("channleid");
//	        			String chup = (String)chmap.get("updatetimer");
//	        			String cid = (String)chmap.get("cid");
//	        			String tmpsql = "";
//	        			if(chup.equals("0"))
//	        				tmpsql = "update news_extends_channel_title set contentstatus=1 where channleid='"+chid+"' and cid='"+cid+"'";
//	        			else
//	        				tmpsql = "update news_extends_channel_title set contentstatus=2 where channleid='"+chid+"' and cid='"+cid+"'";
//	        			sqlStrList.add(tmpsql);
//	        		}
	        		String tmpsql = "update news_extends_channel_title set contentstatus=2 where cid=" +
						"(SELECT cid FROM news_contenttitle where contentid="+content_id+")";
	        		sqlStrList.add(tmpsql);
	        		//--------------
		        	String sql2="delete from t_contents where contentid = "+content_id;
		        	
		        	String sql3="insert into t_contents(contentid,user_id,service_code,genre_id,content_name,content_keyword,content_pubdate,content_duration,conten_info," +
		        			"content_type,content_updateddate,Copyright_deadline,content_status,test_status,audituser,pub_company,area,ordered,content_code,order_success_msg)" +	        			
		        			" select contentid,user_id,lastservice_code,genre_id,content_name,content_keyword,content_pubdate,content_duration,conten_info," +
		        			" content_type,content_updateddate,Copyright_deadline,content_status,test_status,audituser,pub_company,area,ordered,content_code,order_success_msg" +	        			
		        			" from t_auditcontents  where contentid = "+content_id;
		        	
		        	String sql4="delete from t_channel_contents where contentid = "+content_id;
		        	
		        	String sql5="insert into t_channel_contents(channel_id,contentid) " +
		        			" select channel_id,contentid from t_channel_auditcontent where contentid = "+content_id;
		        	
		        	String sql6="delete from t_resource_content where contentid = "+content_id;
		        	
		        	String sql7="insert into t_resource_content(resourceid,contentid) " +
		        			" select resourceid,contentid from t_resource_auditcontent where contentid = "+content_id;
		        	
		        	String sql8 = "delete from t_application_content where contentid = "+content_id;
		        	String sql9 = "insert into t_application_content (contentid,strategy,language,online,version,cldc_version,midp_version,audituser,ordered,service_count) " +
		        			" select contentid,strategy,language,online,version,cldc_version,midp_version,audituser,ordered,service_count from t_auditapp_content where contentid = "+content_id;
		        	//插入news_resources news_contenresource
		        	String sql10 = "insert into news_resources (resourcetype,name,size,newformat,fullpath) select 1,tr.resourceid,tr.size,tr.newformat,tr.fullpath " +
		        			"from t_resources tr,t_resource_auditcontent tra where tra.contentid="+content_id+" and tr.type='12' and tr.resourceid=tra.resourceid ";
		        	
		        	String sql11 = "insert into news_contenresource (cid,rid) select nc.cid,nr.rid from news_contenttitle nc,news_resources nr," +
		        			"t_resource_auditcontent tra,t_resources tr where tra.contentid="+content_id+" and tr.resourceid=tra.resourceid " +
		        					"and tr.type='12' and nr.resourcetype=1 and nc.contentid=tra.contentid and nr.name=tra.resourceid";
		        	
		        	sqlStrList.add(sql2);
		        	sqlStrList.add(sql3);
		        	sqlStrList.add(sql4);
		        	sqlStrList.add(sql5);
		        	sqlStrList.add(sql6);
		        	sqlStrList.add(sql7);
		        	sqlStrList.add(sql8);
		        	sqlStrList.add(sql9);
		        	sqlStrList.add(sql10);
		        	sqlStrList.add(sql11);
	        	}
//	        	String [] sql = sqlStrList.toArray(new String[10]);

	            
	            	this.execTransaction(sqlStrList);
	            } catch (Exception e) {
	            	log.info(content_id+" audit fail !!!" +e.getMessage());
	            	return false;
	            }
	        }
	    	return true;
	    	
        }
        else
        	return false;
        
        
    }  

    public boolean testPass(DataMap hashMap,String status) {
    	String content_id_list = (String)hashMap.get("content_id_list");
    	
        if(content_id_list!=null && !content_id_list.equals(""))
        {
        	String[] c_id_strList=content_id_list.split(",");
        	for(String contentStr:c_id_strList)
	        {
        		String[] idAndAuditStatus = contentStr.split("/");
	            String content_id = "'" + idAndAuditStatus[0] + "'";
	            String content_status = "'" + idAndAuditStatus[1] + "'";
	            String user_id = super.ObjectToStringDB(hashMap.get("user_id"));
	            
	        	//修改状态	            
	        	String sql1="update t_auditcontents set test_status='1' where contentid = "+content_id;
	        	//phase2 add update news_extends_channel_title set istest = 1
	        	String sqlNew="update news_extends_channel_title set istest=1 where cid =(SELECT cid FROM news_contenttitle where contentid= "+content_id +")";
	        	ArrayList<String> sqlStrList = new ArrayList<String>();
	        	sqlStrList.add(sql1);
	        	sqlStrList.add(sqlNew);
//	        	sqlStrList.add(sqlUpDateAuditAppContent);
	        	ArrayList chList = null;
	        	//发布 所有表 条件audit_status=1 审核通过+测试通过
	        	try {
	        	if(content_status.equals("'pass'"))
	        	{
	        		//转换图片 放在上线时做 这样可以避免重新上传文件后还需要审核的情况
		            String resourceid = this.scaleImage(content_id);
		            if(resourceid == null)
		            	return false;
		            else if(resourceid!=null && !resourceid.equals(""))
		            {
		            	String upConIconSql = "update news_contenttitle set contenticon=(select max(rid) from news_resources where name='"+resourceid+"') where contentid="+content_id;
		            	sqlStrList.add(upConIconSql);
		            }
	        		// add phase2 查询对应栏目的更新方式
	        		// modify 0928
//	        		chList = db.queryALLResultSet("SELECT nec.channleid,nec.updatetimer,nc.cid FROM news_extends_channel nec,news_extends_channel_title ncc," +
//	        				"news_contenttitle nc where nc.contentid= "+content_id+" and nec.channleid=ncc.channleid and ncc.cid=nc.cid ");
//	        		//update news_extends_channel_title where chid cid
//	        		for(int i = 0;i<chList.size();i++)
//	        		{
//	        			DataMap chmap = (DataMap)chList.get(i);
//	        			String chid = (String)chmap.get("channleid");
//	        			String chup = (String)chmap.get("updatetimer");
//	        			String cid = (String)chmap.get("cid");
//	        			String tmpsql = "";
//	        			if(chup.equals("0"))
//	        				tmpsql = "update news_extends_channel_title set contentstatus=1 where channleid='"+chid+"' and cid='"+cid+"'";
//	        			else
//	        				tmpsql = "update news_extends_channel_title set contentstatus=2 where channleid='"+chid+"' and cid='"+cid+"'";
//	        			sqlStrList.add(tmpsql);
//	        		}
	        		String tmpsql = "update news_extends_channel_title set contentstatus=2 where cid=" +
						"(SELECT cid FROM news_contenttitle where contentid="+content_id+")";
	        		sqlStrList.add(tmpsql);
	        		//--------------
	        		
		        	String sql2="delete from t_contents where contentid = "+content_id;
		        	
		        	String sql3="insert into t_contents(contentid,user_id,service_code,genre_id,content_name,content_keyword,content_pubdate,content_duration,conten_info," +
		        			"content_type,content_updateddate,Copyright_deadline,content_status,test_status,audituser,pub_company,area,ordered,content_code,order_success_msg)" +	        			
		        			" select contentid,user_id,lastservice_code,genre_id,content_name,content_keyword,content_pubdate,content_duration,conten_info," +
		        			" content_type,content_updateddate,Copyright_deadline,content_status,test_status,audituser,pub_company,area,ordered,content_code,order_success_msg" +	        			
		        			" from t_auditcontents  where contentid = "+content_id;
		        	
		        	String sql4="delete from t_channel_contents where contentid = "+content_id;
		        	
		        	String sql5="insert into t_channel_contents(channel_id,contentid) " +
		        			" select channel_id,contentid from t_channel_auditcontent where contentid = "+content_id;
		        	
		        	String sql6="delete from t_resource_content where contentid = "+content_id;
		        	
		        	String sql7="insert into t_resource_content(resourceid,contentid) " +
		        			" select resourceid,contentid from t_resource_auditcontent where contentid = "+content_id;
		        	
		        	String sql8 = "delete from t_application_content where contentid = "+content_id;
		        	String sql9 = "insert into t_application_content (contentid,strategy,language,online,version,cldc_version,midp_version,audituser,ordered,service_count) " +
		        			" select contentid,strategy,language,online,version,cldc_version,midp_version,audituser,ordered,service_count from t_auditapp_content where contentid = "+content_id;
		        	
		        	String sql10 = "insert into news_resources (resourcetype,name,size,newformat,fullpath) select 1,tr.resourceid,tr.size,tr.newformat,tr.fullpath " +
        				"from t_resources tr,t_resource_auditcontent tra where tra.contentid="+content_id+" and tr.type='12' and tr.resourceid=tra.resourceid ";
        	
		        	String sql11 = "insert into news_contenresource (cid,rid) select nc.cid,nr.rid from news_contenttitle nc,news_resources nr," +
        				"t_resource_auditcontent tra,t_resources tr where tra.contentid="+content_id+" and tr.resourceid=tra.resourceid " +
        					"and tr.type='12' and nr.resourcetype=1 and nc.contentid=tra.contentid and nr.name=tra.resourceid";
        	
		        	sqlStrList.add(sql2);
		        	sqlStrList.add(sql3);
		        	sqlStrList.add(sql4);
		        	sqlStrList.add(sql5);
		        	sqlStrList.add(sql6);
		        	sqlStrList.add(sql7);
		        	sqlStrList.add(sql8);
		        	sqlStrList.add(sql9);
		        	sqlStrList.add(sql10);
		        	sqlStrList.add(sql11);
	        	}
//	        	String [] sql = sqlStrList.toArray(new String[10]);

	           
	            	this.execTransaction(sqlStrList);
	            } catch (Exception e) {
	            	log.info(content_id+" test fail !!!"+e.getMessage());
	            	return false;
	            }
	        }
	    	return true;
	    	
        }
        else
        	return false;
        
        
    }
    
    public boolean insertAuthor(DataMap hashMap) {
        String sql = "insert into t_author (author_id,author_name,author_email,author_info)VALUES( ";
        String author_id = super.ObjectToStringDB(hashMap.get("author_id"));
        String author_name = super.ObjectToStringDB(hashMap.get("author_name"));
        String author_email = super.ObjectToStringDB(hashMap.get("author_email"));
        String author_info = super.ObjectToStringDB(hashMap.get("author_info"));
     
        sql = sql + author_id + ",";
        sql = sql + author_name + ",";
        sql = sql + author_email + ",";
        sql = sql + author_info + ")";
        hashMap = new DataMap();

        
        try {
           this.updateNativeQuery(sql);
            return true;
        } catch (Exception e) {
            return false;
        }
    }

    public boolean insertPublish(DataMap hashMap) {
        String sql = "insert into t_publish (publish_id,publish_name,publish_email,publish_tel,publish_info)VALUES( ";
        String publish_id = super.ObjectToStringDB(hashMap.get("publish_id"));
        String publish_name = super.ObjectToStringDB(hashMap.get("publish_name"));
        String publish_email = super.ObjectToStringDB(hashMap.get("publish_email"));
        String publish_tel = super.ObjectToStringDB(hashMap.get("publish_tel"));
        String publish_info = super.ObjectToStringDB(hashMap.get("publish_info"));
     
        sql = sql + publish_id + ",";
        sql = sql + publish_name + ",";
        sql = sql + publish_email + ",";
        sql = sql + publish_tel + ",";
        sql = sql + publish_info + ")";
        hashMap = new DataMap();

        
        try { this.updateNativeQuery(sql);
        	return true;
          
        } catch (Exception e) {
            return false;
        }
    }
    
    public boolean insertResource(DataMap hashMap) {
        StringBuffer sqlB = new StringBuffer();
        String resource_id = super.ObjectToStringDB(hashMap.get("resource_id"));
        Object content_id = hashMap.get("content_id");
        String useragent = super.ObjectToStringDB(hashMap.get("useragent"));
        String name = super.ObjectToStringDB(hashMap.get("name"));
        long size = super.getlong(hashMap.get("size"));
        String type = super.ObjectToStringDB(hashMap.get("type"));
        String spcode = super.ObjectToStringDB(hashMap.get("spcode"));
        String url = super.ObjectToStringDB(hashMap.get("url"));
        String format = super.ObjectToStringDB(hashMap.get("format"));
        String distributorid = super.ObjectToStringDB(hashMap.get("distributorid"));
        //add newformat fullpath
        String newformat = SysProperty.getPrep("news_imageformat");
        if(newformat == null || newformat.equals(""))
        	newformat = "jpg";
        if(format.lastIndexOf("_")>0)
        	format = "'"+format.substring(format.lastIndexOf("_")+1);
        String fullpath = SysProperty.getPrep("uploadpath")+"/"+spcode.replace("'", "")+"/"+type.replace("'", "")+"/"+curdate+"/"+url.replace("'", "")+"."+format.replace("'", "");
        String sql = "insert into t_resources (resourceid,name,size,type,spcode,url,format,distributorid,newformat,fullpath) VALUES ( ";
        if(content_id != null)
        {
        	sql = "insert into t_resources (resourceid,contentid,name,size,type,spcode,url,format,distributorid,newformat,fullpath) VALUES ( ";
	        if(type.equals("'3'"))
	        {
	        	sql = "insert into t_resources (resourceid,contentid,useragents,name,size,type,spcode,url,format,distributorid,newformat,fullpath) VALUES ( ";
	        }
   		}
        sqlB.append(sql);
        
        sqlB.append(resource_id).append(",");
        if(content_id != null)
        {
	        content_id = super.ObjectToStringDB(content_id);
        	sqlB.append(content_id).append(",");
        	if(type.equals("'3'"))
	        {
	        	sqlB.append(useragent).append(",");
	        }
        }
        sqlB.append(name).append(",");
        sqlB.append(size).append(",");
        sqlB.append(type).append(",");
        sqlB.append(spcode).append(",");
        sqlB.append(url).append(",");
        sqlB.append(format).append(",");
        sqlB.append(distributorid).append(",");
        sqlB.append("'"+newformat+"'").append(",");
        sqlB.append("'"+fullpath+"'").append(")");
        hashMap = new DataMap();
        
        try {this.updateNativeQuery(sqlB.toString());
            return true;
        } catch (Exception e) {
        	log.info(" insertResource fail !!!" +e.getMessage());
            return false;
        }
    }    
    
    public boolean insertReUploadResource(DataMap hashMap) {
        StringBuffer sqlB = new StringBuffer();
        String resource_id = super.ObjectToStringDB(hashMap.get("resource_id"));
        Object content_id = super.ObjectToStringDB(hashMap.get("content_id"));
        String useragent = super.ObjectToStringDB(hashMap.get("useragent"));
        String name = super.ObjectToStringDB(hashMap.get("name"));
        long size = super.getlong(hashMap.get("size"));
        String type = super.ObjectToStringDB(hashMap.get("type"));
        String spcode = super.ObjectToStringDB(hashMap.get("spcode"));
        String url = super.ObjectToStringDB(hashMap.get("url"));
        String format = super.ObjectToStringDB(hashMap.get("format"));
        String distributorid = super.ObjectToStringDB(hashMap.get("distributorid"));
        String newformat = SysProperty.getPrep("news_imageformat");
        if(newformat == null || newformat.equals(""))
        	newformat = "jpg";
        if(format.lastIndexOf("_")>0)
        	//'_100_100_jpg'.substring==>jpg'
        	format = "'"+format.substring(format.lastIndexOf("_")+1);
        String fullpath = SysProperty.getPrep("uploadpath")+"/"+spcode.replace("'", "")+"/"+type.replace("'", "")+"/"+curdate+"/"+url.replace("'", "")+"."+format.replace("'", "");
        String sqlInsertResource = "insert into t_resources (resourceid,contentid,name,size,type,spcode,url,format,distributorid,newformat,fullpath) VALUES ( ";
        sqlB.append(sqlInsertResource);        
        sqlB.append(resource_id).append(",");
        sqlB.append(content_id).append(",");
        sqlB.append(name).append(",");
        sqlB.append(size).append(",");
        sqlB.append(type).append(",");
        sqlB.append(spcode).append(",");
        sqlB.append(url).append(",");
        sqlB.append(format).append(",");
        sqlB.append(distributorid).append(",");
        sqlB.append("'"+newformat+"'").append(",");
        sqlB.append("'"+fullpath+"'").append(")");
        String sqlInsertAuditContentResource = "insert into  t_resource_auditcontent  values (" + resource_id +"," + content_id + ")";
        hashMap = new DataMap();
        ArrayList<String> sqlStrList = new ArrayList<String>();
        sqlStrList.add(sqlB.toString());
        sqlStrList.add(sqlInsertAuditContentResource);
        String [] sql = sqlStrList.toArray(new String[10]);

        try {
        	return this.execTransaction(sql);
        } catch (Exception e) {
        	log.info(" insertReUploadResource fail !!!" +e.getMessage());
            return false;
        }
    }    

//auditBook  
    public boolean updateBookStatus(DataMap hashMap,String status) {
        String sql = "update t_auditcontents set content_status='"+status+"' where contentid in ( ";
        String content_id_list = (String)hashMap.get("content_id_list");
//        String employee_id = super.ObjectToStringDB(hashMap.get("employee_id"));

        sql = sql + content_id_list + ")";
        hashMap = new DataMap();

        
        try {
        	this.updateNativeQuery(sql);
            return true;
        } catch (Exception e) {
        	log.info(" updateBookStatus fail !!!" +e.getMessage());
            return false;
        }
    }
    
    public boolean updateOrderMsg(DataMap hashMap)
    {
    	String order_success_msg = (String)(hashMap.get("order_success_msg"));
    	String idandstatus = (String)(hashMap.get("content_id"));
    	String content_id = idandstatus.substring(0,idandstatus.lastIndexOf("/"));
    	String sql = "";
    	String sql2 = "";
    	if(super.StringIsNotNull(content_id))
    	{
    		sql = "update t_contents set order_success_msg='"+order_success_msg+"' where contentid='"+content_id+"'";
    		sql2 = "update t_auditcontents set order_success_msg='"+order_success_msg+"' where contentid='"+content_id+"'";
    	}
    	String[] sqlStr = new String[2];
    	sqlStr[0] = sql;
    	sqlStr[1] = sql2;
    	try {
    		return this.execTransaction(sqlStr);
        } catch (Exception e) {
        	log.info(" updateOrderMsg fail !!!" +e.getMessage());
            return false;
        }
    }
    
    public boolean updateBookStatus(DataMap hashMap,String status,String cause) {
        String sql = "update t_auditcontents set content_status='"+status+"',cause='"+cause+"'  ";
        sql = sql + "where contentid in ( ";

        String content_id_list = (String)hashMap.get("content_id_list");
        sql = sql + content_id_list + ")";
        hashMap = new DataMap();
        
        try {
           this.updateNativeQuery(sql);
            return true;
        } catch (Exception e) {
        	log.info(" updateBookStatus fail !!!" +e.getMessage());
            return false;
        }
    }     
    
    public boolean updateResourceUa(String useragent,String resourceid) {
        String sql = "update t_resources set useragents='"+useragent+"' where resourceid='" + resourceid + "'";
        try {
        	 this.updateNativeQuery(sql);
             return true;
        } catch (Exception e) {
        	log.info(" updateResourceUa fail !!!" +e.getMessage());
        	return false;
        }
    }
    public String getCurrentUaClass(String resourceid) {
    	String sql = "";
    	if(resourceid != null && !resourceid.equals(""))
        	sql = "SELECT useragents FROM t_resources t where resourceid='" + resourceid + "'";
        try {
            return this.queryOne(sql);
        } catch (Exception e) {
        	log.info(" get current uaclass id fail !!!" +e.getMessage());
        	return "";
        }
    }
//    public ArrayList getCurrentUaClassList(String resourceid) {
//    	String sql = "";
//    	if(resourceid != null && !resourceid.equals(""))
//        	sql = "select * FROM t_ua_class where FIND_IN_SET(ua_class_id,( SELECT useragents FROM t_resources  where resourceid='"+resourceid+"')) >0 ";
//        try {
//            return this.queryALLResultSet(sql);
//        } catch (Exception e) {
//        	log.info(" get current uaclass list fail !!!" +e.getMessage());
//        	return null;
//        }
//    }
    
    public boolean delUaclassByResid(String resourceid,String uaclassid)
    {
    	
    	if(resourceid != null && !resourceid.equals(""))
        	sql = "select useragents FROM t_resources where resourceid ='"+resourceid+"'";
    	try {
	    	String useragents =this.getOneString();
	    	if(uaclassid != null)
	    	{
	    		String uaclassidstr = uaclassid + ",";
	    		String uaclsidstr = ","+uaclassid;
	    		if(useragents.contains(uaclassidstr))
	    			useragents = useragents.replace(uaclassidstr, "");
	    		else if(useragents.contains(uaclsidstr))
	    			useragents = useragents.replace(uaclsidstr, "");
	    		else if(useragents.contains(uaclassid))
	    			useragents = useragents.replace(uaclassid, "");
	    	}
	    	sql = "update t_resources set useragents='"+useragents+"' where resourceid='"+resourceid+"'";
	    	 this.updateNativeQuery(sql);
             return true;
        } catch (Exception e) {
        	log.info(" delUaclassByResid fail !!!" +e.getMessage());
        	return false;
        }
        
    }
    
    public boolean checkContentCode(String contentcode,String contentid,String userid) 
    {
//        String sql = "SELECT contentid FROM t_auditcontents t where content_code='" + contentcode + "'";
//        if(contentid != null && !contentid.equals(""))
//        {
//        	sql = sql+"and contentid != '"+contentid+"' ";
//        }
//        if(userid != null && !userid.equals(""))
//        {
//        	sql = sql+"and user_id = '"+userid+"' ";
//        }
    	String sql = "select contentid from t_auditcontents t,t_employee te,t_user tu where t.content_code='"+contentcode+"' and " +
    			"t.user_id=tu.user_id and tu.employee_id=te.employee_id and te.sp_code=" +
    			"(select e.sp_code from t_user u,t_employee e where e.employee_id=u.employee_id and u.user_id='"+userid+"')";
        if(contentid != null && !contentid.equals(""))
        {
        	sql = sql+" and t.contentid != '"+contentid+"' ";
        }
        try {
            return this.queryExist(sql);
        } catch (Exception e) {
        	log.info(" checkContentCode fail !!!" +e.getMessage());
        	return true;
        }
    }
    //add for multi catalog
//    public ArrayList getChannelPlatform()
//    {
//    	
//    	ArrayList result = new ArrayList();
//    	//1 取得所有生效的catalog对应的catalogchannelid
//    	sql = "SELECT ncc.channelid,ncp.* FROM news_catlog nc left join news_catlog_platform ncp on ncp.catlogid=nc.catlogid," +
//    			"news_catlog_channel ncc where nc.isnowpublish in (1,2) and nc.catlogid=ncc.catlogid";
//    	ArrayList catalogChannelidAndPlatformList = new ArrayList();
//    	try {
//    		catalogChannelidAndPlatformList = this.queryALLResultSet(sql);
//    		if(catalogChannelidAndPlatformList.size()>0)
//    		{
//	    		for(int i=0;i<catalogChannelidAndPlatformList.size();i++)
//	    		{
//	    			DataMap lastChannelAndPlatform = new DataMap();
//	    			HashMap hashmap = (HashMap)catalogChannelidAndPlatformList.get(i);
//	    			String catalogChannelid = (String)hashmap.get("channelid");
//	    			String platforminfo = InterUtil.rb.getString("src.gameplatform")+hashmap.get("mplatform")+"."+
//	    			InterUtil.rb.getString("src.gamedistributor")+hashmap.get("magent")+"."+InterUtil.rb.getString("src.clientsn")+
//	    			hashmap.get("mserialnum")+"."+InterUtil.rb.getString("src.languagearea")+hashmap.get("mlocale");
//	    			sql = "SELECT nc.channel_id FROM news_buttons nb,news_extends_firstchannel_buttons nfb,news_contenttype nc where " +
//	    					"nfb.channelid="+catalogChannelid+" and nc.newscontenttype=nb.buttoncontenttype and nfb.buttonid=nb.buttonid";
//	    			ArrayList tchannelIdList = this.queryALLResultSet(sql);
//	    			if(tchannelIdList.size()>0)
//	    			{
//	    				//首先要判断结果集里的channel是否最后一级
//	    				for(int j=0;j<tchannelIdList.size();j++)
//	    				{
//	    					DataMap tmpMap = (DataMap)tchannelIdList.get(j);
//	    					String tch_id = tmpMap.getMapData("channel_id");
//	    					if(tch_id == null || tch_id.equals(""))
//	    						continue;
//	    					sql = "select function_name from t_channels where channel_id='"+tch_id+"'";
//	    					String functionname =this.getOneString();
//	    					//if最后一级 放到map里 key是最后一级的id value是platforminfo
//	    					if(functionname.toUpperCase().equals("LAST") || functionname.toUpperCase().equals("CHANNELSONG"))
//	    						lastChannelAndPlatform.put(tch_id, platforminfo);
//	    					//不是 递归查询
//	    					else
//	    						buildLastChannelAndPlatform(tch_id,platforminfo,lastChannelAndPlatform);
//	    				}
//	    			}
//	    			result.add(lastChannelAndPlatform);
//	    		}
//    		}
//		} catch (Exception e) {
//			log.info(" java bean getChannelPlatform fail !!!" +e.getMessage());
//			e.printStackTrace();
//		}
//    	return result;
//    }
    
    private void buildLastChannelAndPlatform(String tch_id,String platforminfo,DataMap lastChannelAndPlatform)
    {
    	String sql = "SELECT channel_id,function_name FROM t_channels where previous_id='"+tch_id+"'";
    	try {
			ArrayList chList = this.queryALLResultSet(sql);
			for(int i=0;i<chList.size();i++)
			{
				HashMap hashMap = (HashMap)chList.get(i);
				String fnName = (String)hashMap.get("function_name");
				String channel_id = (String)hashMap.get("channel_id");
				if(fnName.toUpperCase().equals("LAST") || fnName.toUpperCase().equals("CHANNELSONG"))
					lastChannelAndPlatform.put(channel_id, platforminfo);
				else
					buildLastChannelAndPlatform(channel_id,platforminfo,lastChannelAndPlatform);
			}
		} catch (Exception e) {
			log.info(" java bean buildLastChannelAndPlatform fail !!!" +e.getMessage());
			e.printStackTrace();
		}
    }
    /*
    public ArrayList<String> getCatalogChannelidList(DBOperate db,String lastPreviouChannelid)
    {
    	String sql = "SELECT nfb.channelid FROM news_contenttype nc,news_buttons nb,news_extends_firstchannel_buttons nfb " +
    			"where nc.channelid="+lastPreviouChannelid+" and nc.newscontenttype=nb.buttoncontenttype and nfb.buttonid=nb.buttonid";
    	ArrayList<String> tempchidList = new ArrayList<String>();
    	ArrayList<String> catalogChannelidList = new ArrayList<String>();
    	try {
    		tempchidList = db.queryALLResultSet(sql);
    		if(tempchidList.size()>0)
    		{
				for(String channelid : tempchidList)
				{
					if(isCatalogChannelid(db,channelid))
						catalogChannelidList.add(channelid);
					else
						catalogChannelidList = getCatalogChannelidList(db,channelid);
				}
    		}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return catalogChannelidList;
    }
    
    public boolean isCatalogChannelid(DBOperate db,String channelid)
    {
    	String sql = "SELECT tc.channel_id FROM news_extends_firstchannel nfc,t_channels tc " +
    			"where nfc.channelid="+channelid+" and nfc.channel_id=tc.channel_id and tc.function_name='FIRST' and tc.level=0";
    	String channel_id = "";
    	try {
    		channel_id = db.queryOne(sql);
		} catch (Exception e) {
			log.info(" isCatalogChannelid fail !!!" +e.getMessage());
			e.printStackTrace();
			return false;
		}
		if(channel_id != null && !channel_id.equals(""))
			return true;
		else
			return false;
    }
    */
    //-----------
    //phase2 get iconlist
//    public ArrayList getIconList() {
//		String querySql = "SELECT * FROM news_resources where isusebysys=1 and resourcetype=1";
//		try {
//			return this.queryALLResultSet(querySql);
//		} catch (Exception e) {
//			log.info(" java bean getCurrentIcon fail !!!" +e.getMessage());
//			return null;
//		}
//	}
//  phase2 get curicon
//    public DataMap getCurrentIcon(String contentid_id) {
//		String querySql = "select nr.* from news_resources nr where rid = (SELECT contenticon FROM news_contenttitle where contentid='"+contentid_id+"')";
//		DataMap a = null;
//		try {
//			//a= this.queryOneRow(querySql);
//			return a;
//		} catch (Exception e) {
//			log.info(" java bean getCurrentIcon fail !!!" +e.getMessage());
//			return null;
//		}
//	}
    //add phase2 reset content to channel
    public boolean resetConToChannel(DataMap hashMap)
    {
    
    	String content_id = super.ObjectToStringDB(hashMap.get("content_id"));
    	String test_status = super.ObjectToString(hashMap.get("test_status"));
    	String content_status = super.ObjectToString(hashMap.get("content_status"));
    	String temp=(String)hashMap.get("channelid");
        String [] channelid=temp.split(",");
		ArrayList<String> sqlStrList = new ArrayList<String>();
		String sqlDelChannelAudit = "delete from t_channel_auditcontent where contentid="+content_id;
		String sqlDelChannelContent = "";
		//如果审核通过测试通过 表示当前内容是已经发布的内容 在t_contents t_channel_contents里有对应的数据
		if(content_status.toLowerCase().equals("pass") && test_status.equals("1"))
		{
			sqlDelChannelContent = "delete from t_channel_contents where contentid="+content_id;
		}
		String sqlDelNewChannel = "delete from news_extends_channel_title where cid=(SELECT cid FROM news_contenttitle where contentid="+content_id+")";
		sqlStrList.add(sqlDelChannelAudit);
		if(sqlDelChannelContent.length()>0)
				sqlStrList.add(sqlDelChannelContent);
		sqlStrList.add(sqlDelNewChannel);
		String tempSql="insert into t_channel_auditcontent(contentid,channel_id)VALUES( "+content_id + ",";
		String tempPassSql="insert into t_channel_contents(contentid,channel_id)VALUES( "+content_id + ",";
		String newChSql="insert into news_extends_channel_title(channleid,cid,contentstatus,istest,isnew)VALUES(";
		
		try {
			for(int i=0;i<channelid.length;i++)
			{
				sqlStrList.add(tempSql+"'"+channelid[i]+"')");
				if(content_status.toLowerCase().equals("pass") && test_status.equals("1"))
				{
					sqlStrList.add(tempPassSql+"'"+channelid[i]+"')");
				}
				String chupdatetimer = this.getOneString("select updatetimer from news_extends_channel where channel_id='"+channelid[i]+"'");
				if(chupdatetimer != null && chupdatetimer.equals("0"))
					sqlStrList.add(newChSql+"(select channleid from news_extends_channel where channel_id='"+channelid[i]+"')," +
							"(SELECT cid FROM news_contenttitle where contentid="+content_id+"),1,"+test_status+",1)");
				else
					sqlStrList.add(newChSql+"(select channleid from news_extends_channel where channel_id='"+channelid[i]+"')," +
							"(SELECT cid FROM news_contenttitle where contentid="+content_id+"),2,"+test_status+",1)");
			}
			return this.execTransaction(sqlStrList);
        } catch (Exception e) {
        	log.info(" resetConToChannel fail !!!" +e.getMessage());
            return false;
        }
    }
    //add 1119 select channel update
    public DataMap buildLastChannelMap()
    {
    	
    	sql = "SELECT channel_id,channel_name,function_name,previous_id FROM t_channels t";
    	HashMap<String,String> childIdAndPreiousId = new HashMap<String,String>();
    	HashMap<String,String> idAndName = new HashMap<String,String>();
    	DataMap result = new DataMap();
    	List chList = null;
    	try {
    		System.out.println(sql);
			chList = this.queryALLResultSet(sql);
		} catch (Exception e) {
			log.info(" java bean buildChChildIdAndPreviousIdMap fail !!!" +e.getMessage());
			e.printStackTrace();
			return null;
		}
		//首先建立两个map准备数据
		for(int i=0;i<chList.size();i++)
		{
			HashMap hashMap = (HashMap)chList.get(i);
			String channel_id = (String)hashMap.get("channel_id");
			String chName = (String)hashMap.get("channel_name");
			String fnName = (String)hashMap.get("function_name");
			String previous_id = (String)hashMap.get("previous_id");
			//先将id和name装入map
			idAndName.put(channel_id, chName);
			//channel如果是normal或者first,就装入map,key是channel_id,value是
			if(fnName.equals(BookConfig.channel_first) || fnName.equals(BookConfig.channel_normal))
			{
				childIdAndPreiousId.put(channel_id, previous_id);
			}
		}
		//build map,key:channleid value:previousid+name
		for(int i=0;i<chList.size();i++)
		{
			HashMap hashMap = (HashMap)chList.get(i);
			String channel_id = (String)hashMap.get("channel_id");
			String chName = (String)hashMap.get("channel_name");
			String fnName = (String)hashMap.get("function_name");
			String previous_id = (String)hashMap.get("previous_id");
			//如果是normal或者first,就装入map,key是channel_id,value是
			if(fnName.equals(BookConfig.channel_last) || fnName.equals(BookConfig.channel_song))
			{
				String previousChName = idAndName.get(previous_id);
				chName = chName+"="+previousChName;
				chName = getValue(childIdAndPreiousId,idAndName,previous_id,chName);
				//最上一级的频道名称必然是news,把news过滤掉
				chName = chName.substring(0,chName.lastIndexOf("="));
				String[] tmp = chName.split("=");
				String value = "";
				for(int j=tmp.length-1;j>=0;j--)
				{
					value=value+tmp[j]+"--";
				}
				value = value.substring(0,value.length()-2);
				result.put(channel_id, value);
			}
		}
    	return result;
    }
    
    private String getValue(HashMap<String,String> idmap,HashMap<String,String> namemap,String key,String result)
    {
    	String parentid = idmap.get(key);
    	String parentname = namemap.get(parentid);
    	if((key != null && parentid!=null) && !parentid.equals(key))
    	{
    		result = result+"="+parentname;
    		return getValue(idmap,namemap,parentid,result);
    	}
    	else
    	{
    		return result;
    	}
    }
    
    public List getChannelsbyGame(String contentid)
	{
		String sql = "select tc.channel_id,tc.channel_name from news_contenttitle nc,t_channels tc,news_extends_channel_title nect,news_extends_channel nec " +
		"where nc.contentid='"+contentid+"' and nc.cid=nect.cid and nect.channleid=nec.channleid and tc.channel_id=nec.channel_id";
		try {
			return this.queryALLResultSet(sql);
		} catch (Exception e) {
			log.info(" getChannelsbyGame fail !!!" +e.getMessage());
			return null;
		}
	}
    
    
    /**
     * 获得主题资源
     * @param resourceid
     * @return
     */
//    public DataMap getSubject_Resource(String  resourceid) {
//
//    	String sql = "select * from t_subject_resources where resourceid= '" + resourceid + "'";
//        try {
//            return null;//this.queryOneRow(sql);
//        } catch (Exception e) {
//        	log.info(" getResource fail !!!" +e.getMessage());
//            return null;
//        }
//    } 
    
    /**
     * 主题 CurrentUaClass
     * @param resourceid
     * @return
     */
    public String getCurrentUaClass_theme(String resourceid) {
    	String sql = "";
    	if(resourceid != null && !resourceid.equals(""))
        	sql = "SELECT useragents FROM t_subject_resources t where resourceid='" + resourceid + "'";
        try {
            return this.queryOne(sql);
        } catch (Exception e) {
        	log.info(" get current uaclass id fail !!!" +e.getMessage());
        	return "";
        }
    }
    
    /**
     * 主题 CurrentUaClassLis
     * @param resourceid
     * @return
     */
//    public ArrayList getCurrentUaClassList_theme(String resourceid) {
//    	String sql = "";
//    	if(resourceid != null && !resourceid.equals(""))
//        	sql = "select * FROM t_ua_class where FIND_IN_SET(ua_class_id,( SELECT useragents FROM t_subject_resources  where resourceid='"+resourceid+"')) >0 ";
//        try {
//            return this.queryALLResultSet(sql);
//        } catch (Exception e) {
//        	log.info(" get current uaclass list fail !!!" +e.getMessage());
//        	return null;
//        }
//    }
    
    /**
     * 主题 updateSubjectResourceUa
     * @param useragent
     * @param resourceid
     * @return
     */
    public boolean updateSubjectResourceUa(String useragent,String resourceid) {
        String sql = "update t_subject_resources set useragents='"+useragent+"' where resourceid='" + resourceid + "'";
        try {
            this.updateNativeQuery(sql);
            return true;
        } catch (Exception e) {
        	log.info(" updateResourceUa fail !!!" +e.getMessage());
        	return false;
        }
    }
    
    /***
     * 删除UA组  主题
     * @param resourceid
     * @param uaclassid
     * @return
     */
    public boolean delUaclassBySubjectResid(String resourceid,String uaclassid)
    {
    
    	
    	if(resourceid != null && !resourceid.equals(""))
        	sql = "select useragents FROM t_subject_resources where resourceid ='"+resourceid+"'";
    	try {
	    	String useragents =this.getOneString();
	    	if(uaclassid != null)
	    	{
	    		String uaclassidstr = uaclassid + ",";
	    		String uaclsidstr = ","+uaclassid;
	    		if(useragents.contains(uaclassidstr))
	    			useragents = useragents.replace(uaclassidstr, "");
	    		else if(useragents.contains(uaclsidstr))
	    			useragents = useragents.replace(uaclsidstr, "");
	    		else if(useragents.contains(uaclassid))
	    			useragents = useragents.replace(uaclassid, "");
	    	}
	    	sql = "update t_subject_resources set useragents='"+useragents+"' where resourceid='"+resourceid+"'";
	    	this.updateNativeQuery(sql);
	    	return  true;
        } catch (Exception e) {
        	log.info(" delUaclassByResid fail !!!" +e.getMessage());
        	return false;
        }
        
    }
    
    /**
     * 删除主题资源文件 重新上传文件
     * @param resourceid
     * @param content_id
     * @return
     */
    public boolean delThemeResourceById(String resourceid,String content_id)  {
    	ArrayList<String> sqlStrList = new ArrayList<String>();
        String sql1 = "";
        String sql2 = "";
        String sqlInsert = "";
        String deleteNews = "";
        if(resourceid != null && !resourceid .equals(""))
        {
        	sqlInsert = "insert into t_resourcedelete (type,url,format) (select ts.type,ts.url,ts.format from t_subject_resources ts where ts.resourceid='" + resourceid + "')";
        	sqlStrList.add(sqlInsert);
        	sql1 = "delete from t_subject_resources where resourceid='" + resourceid + "'";
        	sqlStrList.add(sql1);
        	deleteNews = "delete from news_resources where name='"+ resourceid + "'";
        	sqlStrList.add(deleteNews);
        }
        try {
        	boolean bool=this.execTransaction(sqlStrList);
            return bool;
        } catch (Exception e) {
        	log.info(" delResourceById fail !!!" +e.getMessage());
            return false;
        }
    }    
    
    
    /**
     * 获得电子书资源
     * @param resourceid
     * @return
     */
//    public DataMap getEbook_Resource(String  resourceid) {
//
//    	String sql = "select * from t_ebook_resource where resourceid= '" + resourceid + "'";
//        try {
//        	 return null;
////            return this.queryOneRow(sql);
//        } catch (Exception e) {
//        	log.info(" getResource fail !!!" +e.getMessage());
//            return null;
//        }
//    } 
    
    /**
     * 电子书 CurrentUaClassLis
     * @param resourceid
     * @return
     */
//    public ArrayList getCurrentUaClassList_ebook(String resourceid) {
//    	String sql = "";
//    	if(resourceid != null && !resourceid.equals(""))
//        	sql = "select * FROM t_ua_class where FIND_IN_SET(ua_class_id,( SELECT useragent FROM t_ebook_resource  where resourceid='"+resourceid+"')) >0 ";
//        try {
//            return this.queryALLResultSet(sql);
//        } catch (Exception e) {
//        	log.info(" get current uaclass list fail !!!" +e.getMessage());
//        	return null;
//        }
//    }
    
    /***
     * 删除UA组  电子书
     * @param resourceid
     * @param uaclassid
     * @return
     */
    public boolean delUaclassByEbookResid(String resourceid,String uaclassid)
    {
    	String sql = "";
    	
    	if(resourceid != null && !resourceid.equals(""))
        	sql = "select useragent FROM t_ebook_resource where resourceid ='"+resourceid+"'";
    	try {
	    	String useragents =this.getOneString();// db.queryOne(sql);
	    	if(uaclassid != null)
	    	{
	    		String uaclassidstr = uaclassid + ",";
	    		String uaclsidstr = ","+uaclassid;
	    		if(useragents.contains(uaclassidstr))
	    			useragents = useragents.replace(uaclassidstr, "");
	    		else if(useragents.contains(uaclsidstr))
	    			useragents = useragents.replace(uaclsidstr, "");
	    		else if(useragents.contains(uaclassid))
	    			useragents = useragents.replace(uaclassid, "");
	    	}
	    	sql = "update t_ebook_resource set useragent='"+useragents+"' where resourceid='"+resourceid+"'";
	    	 this.updateNativeQuery(sql);
	    	 return true;
        } catch (Exception e) {
        	log.info(" delUaclassByResid fail !!!" +e.getMessage());
        	return false;
        }
        
    }
    
    /**
     * 电子书 CurrentUaClass
     * @param resourceid
     * @return
     */
    public String getCurrentUaClass_ebook(String resourceid) {
    	//String sql = "";
    	if(resourceid != null && !resourceid.equals(""))
        	sql = "SELECT useragent FROM t_ebook_resource t where resourceid='" + resourceid + "'";
        try {
            return this.getOneString();
        } catch (Exception e) {
        	log.info(" get current uaclass id fail !!!" +e.getMessage());
        	return "";
        }
    }
    
    /**
     * 电子书 updateEbookResourceUa
     * @param useragent
     * @param resourceid
     * @return
     */
    public boolean updateEbookResourceUa(String useragent,String resourceid) {
        String sql = "update t_ebook_resource set useragent='"+useragent+"' where resourceid='" + resourceid + "'";
        try {
            return this.updateNativeQuery(sql)>0;
        } catch (Exception e) {
        	log.info(" updateResourceUa fail !!!" +e.getMessage());
        	return false;
        }
    }
    
}
 